<template>
	<el-input :value="value" @input="inputChange" :placeholder="placeholder" type="number" :max="max" :min="min"
		:maxlength="maxlength" :minlength="minlength" :disabled="disabled" :step="step"
		@wheel.native.prevent="$inputStopScroll($event)">
		<template slot="suffix">
			<slot name="suffix"></slot>
		</template>
	</el-input>
</template>

<script>
	export default {
		props: {
			name: String,
			max: [String, Number],
			min: {
				type: [String, Number],
				default: 0
			},
			maxlength: Number,
			minlength: Number,
			value: [String, Number],
			step: String,
			size: String,
			resize: String,
			form: String,
			disabled: Boolean,
			readonly: Boolean,
			autofocus: Boolean,
			placeholder: String,
			type: {
				type: String,
				default: 'text'
			},
			rows: {
				type: Number,
				default: 2
			},
			autosize: {
				type: [Boolean, Object],
				default: false
			},
			autocomplete: {
				type: String,
				default: 'off'
			},
			/** @Deprecated in next major version */
			autoComplete: {
				type: String,
				validator(val) {
					process.env.NODE_ENV !== 'production' &&
						console.warn(
							'[Element Warn][Input]\'auto-complete\' property will be deprecated in next major version. please use \'autocomplete\' instead.'
						);
					return true;
				}
			},
			validateEvent: {
				type: Boolean,
				default: true
			},
			suffixIcon: String,
			prefixIcon: String,
			label: String,
			clearable: {
				type: Boolean,
				default: false
			},
			showPassword: {
				type: Boolean,
				default: false
			},
			showWordLimit: {
				type: Boolean,
				default: false
			},
			tabindex: String,
			tofixed: {
				type:[String,Number],
				default: -1
			},
		},
		data() {
			return {}
		},
		watch: {},
		created() {},
		methods: {
			inputChange(e) {
				let tofixed=Number(this.tofixed);
				let value = e ? Number(e) : e,
					maxlength = this.maxlength;
					// console.log(value)
				if (maxlength && maxlength > 0 && value.length > maxlength) {
					value = e.substring(0, maxlength)
				}
				// console.log(value , this.min,value < this.min)		 
				if (value < this.min) {
					value = this.min
					console.log("ccc:",value)
				}
				
				if (tofixed!= -1) {
					if (value) {
						try {
							let StringValue = String(value)
							let values = StringValue.split(".");  
							if (values.length > 1 && values[1].length > tofixed) {
								value = Number(value).toFixed(tofixed)
								// let value2 = values[1].substring(0, this.tofixed)
								// values[1] = value2
								// value = Number(values.join('.'))
							}
						} catch (e) {
							//TODO handle the exception
							console.log(e)
						} 
					}
				}
				// console.log("numbervalue:numbervalue:", value)
				this.$emit('update:value', value)
				this.$emit('input', value)
			}
		}
	}
</script>

<style>
</style>
